package com.muchfish.reactor.api;

import reactor.core.publisher.Flux;

import java.time.Duration;

public class ReactorSampleExample {
    public static void main(String[] args) throws InterruptedException {
        Flux<Integer> source = Flux.range(1, 10).delayElements(Duration.ofSeconds(1)); // 模拟延迟;

        // 在2秒钟采样一个元素
        source.sample(Duration.ofSeconds(2)) //数据源1秒一个，采用2秒一次。会漏掉部分数据
                .subscribe(System.out::println);

        // 阻塞主线程，让采样执行完
        Thread.sleep(233333);
    }
}

